Common Lisp
Table of Contents
- 1. Related Articles
- 2. Common Lisp Pathnames
- 3. Common Lisp - onlisp - Paul Graham
- 4. The Elements of AI
- 5. Papers
- 5.1. CLOSminded: Slot Accessor Names Matter
- 5.2. CLOS in Context: The Shape of the Design Space
- 5.3. Performance Beyond Expectations
- 5.4. Using Lisp Internals - Unportable but fun
- 5.4.1. sb-cover can generate coverage report
- 5.4.2. Using Custom Assembly Instructions - An implementation of 32-bit bitwise rotation operators for SBCL’s x86 architecture backend
- 5.4.3. Extensible CLOS method specializers
- 5.4.4. Generic sequences protocol allows easily extending sequence behaviours with slight deviation from standard regarding error-signalling
- 6. Slime Tips
- 7. Git Tips
- 8. CLOS
1. Related Articles
2. Common Lisp Pathnames
How We Got Here
The historical diversity of file systems in existence during the 70s and 80s can be easy to forget. Kent Pitman, one of the principal technical editors of the Common Lisp standard, described the situation once in comp.lang.lisp (Message-ID: sfwzo74np6w.fsf@world.std.com) thusly:
The dominant file systems at the time the design [of Common Lisp] was done were TOPS-10, TENEX, TOPS-20, VAX VMS, AT&T Unix, MIT Multics, MIT ITS, not to mention a bunch of mainframe [OSs]. Some were uppercase only, some mixed, some were case-sensitive but case-translating (like CL). Some had dirs as files, some not. Some had quote chars for funny file chars, some not. Some had wildcards, some didn’t. Some had :up in relative pathnames, some didn’t. Some had namable root dirs, some didn’t. There were file systems with no directories, file systems with non-hierarchical directories, file systems with no file types, file systems with no versions, file systems with no devices, and so on.
If you look at the pathname abstraction from the point of view of any single file system, it seems baroque. However, if you take even two such similar file systems as Windows and Unix, you can already begin to see differences the pathname system can help abstract away–Windows filenames contain a drive letter, for instance, while Unix filenames don’t. The other advantage of having the pathname abstraction designed to handle the wide variety of file systems that existed in the past is that it’s more likely to be able to handle file systems that may exist in the future. If, say, versioning file systems come back into vogue, Common Lisp will be ready.
4. The Elements of AI
4.1. Knowledge Representation
4.1.1. Semantic Networks
4.2. Logical Reasoning
4.3. Probabilistic Reasoning
4.3.1. Dempster-Shafer Calculus
5. Papers
5.1. CLOSminded: Slot Accessor Names Matter
by Tim Moore
In CLOS we should think in terms of generic functions instead of the C++ style of communication between objects.
Don’t prepend class name in accessor names.
When defining protocol class, its is common practice to define a standard subclass of it, especially if it the protocol is implementable in terms of slots.
5.2. CLOS in Context: The Shape of the Design Space
by
- Daniel G. Bobrow
- Richard P. Gabriel
- Jon L. White
Shows the space of OOP system's design, and the aspects of CL.
- Object-Based Programming Tradition
- Data-Driven Dispatch
- Pattern-directed Invocation
- Polymorphism Tradition
Figure 1: Styles of OOP
5.3. Performance Beyond Expectations
This paper illustrates a neat technique to make slot access faster. Instead of using accessor function it uses closure.
"We replace calls to the IREF* generic function with calls to the IREF-FN of the image instance."
< Collapse code block
(defmethod initialize-instance :after ((image array-image-unsigned-byte-8)) (with-slots (iref-fn xmap ymap pixels) (let ((xmap xmap) (ymap ymap) (pixels pixels)) ;; ***** This is the lexical scope of the IREF-FN *********** (flet ((iref-fn (x y) (declare (type fixnum x y)) (aref (the (simple-array (unsigned-byte 8) (*)) pixels) (fix+ (aref (the image-map xmap) x) (aref (the image-map ymap) y))))) (setf iref-fn #’iref-fn))))) (defmacro iref (image x y) ‘(funcall (the function (image-iref-fn ,image) ,x ,y))) (defun iref-image-add0 (a b c) (loop with xdim fixnum = (image-xdim a) with ydim fixnum = (image-ydim a) for y fixnum from 0 below ydim do (loop for x fixnum from 0 below xdim do (setf (iref c x y) (fix+ (iref a x y) (iref b x y))))) c)
5.4. Using Lisp Internals - Unportable but fun
5.4.1. sb-cover can generate coverage report
For example to generate coverage report for cl-ppcre system do:
< Collapse code block
(require :sb-cover) (declaim (optimize sb-cover:store-coverage-data)) (asdf:oos ’asdf:load-op :cl-ppcre-test) (cl-ppcre-test:run-all-tests) (sb-cover:report "/tmp/cl-ppcre/")
5.4.2. Using Custom Assembly Instructions - An implementation of 32-bit bitwise rotation operators for SBCL’s x86 architecture backend
5.4.3. Extensible CLOS method specializers
5.4.4. Generic sequences protocol allows easily extending sequence behaviours with slight deviation from standard regarding error-signalling
6. Slime Tips
6.1. M-? lists all references & C-c C-k recompiles all of them
6.2. C-c C-d ~ Looksup format directive documentation in hyperspec
7. Git Tips
7.1. Improve Git Diffs for Lisp
https://www.n16f.net/blog/improving-git-diffs-for-lisp/
Edit your Git attribute file at $HOME/.gitattributes
and add entries for both Emacs Lisp and Common Lisp:
< Collapse code block
*.lisp diff=common-lisp *.el diff=elisp
Then edit your Git configuration file at $HOME/.gitconfig
and configure the path of the Git attribute file:
< Collapse code block
[core] attributesfile = ~/.gitattributes
Finally, set the regular expression used to match a top-level function name:
< Collapse code block
[diff "common-lisp"] xfuncname="^\\((def\\S+\\s+\\S+)" [diff "elisp"] xfuncname="^\\((((def\\S+)|use-package)\\s+\\S+)"